home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_061 / microemacs / tcap.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  230 lines

  1. /*    tcap:    Unix V5, V7 and BS4.2 Termcap video driver
  2.         for MicroEMACS
  3. */
  4.  
  5. #define    termdef    1            /* don't define "term" external */
  6.  
  7. #include <stdio.h>
  8. #include    "estruct.h"
  9. #include        "edef.h"
  10.  
  11. #if TERMCAP
  12.  
  13. #define    MARGIN    8
  14. #define    SCRSIZ    64
  15. #define    NPAUSE    10            /* # times thru update to pause */
  16. #define BEL     0x07
  17. #define ESC     0x1B
  18.  
  19. extern int      ttopen();
  20. extern int      ttgetc();
  21. extern int      ttputc();
  22. extern int    tgetnum();
  23. extern int      ttflush();
  24. extern int      ttclose();
  25. extern int    tcapkopen();
  26. extern int    tcapkclose();
  27. extern int      tcapmove();
  28. extern int      tcapeeol();
  29. extern int      tcapeeop();
  30. extern int      tcapbeep();
  31. extern int    tcaprev();
  32. extern int    tcapcres();
  33. extern int      tcapopen();
  34. extern int      tput();
  35. extern char     *tgoto();
  36. #if    COLOR
  37. extern    int    tcapfcol();
  38. extern    int    tcapbcol();
  39. #endif
  40.  
  41. #define TCAPSLEN 315
  42. char tcapbuf[TCAPSLEN];
  43. char *UP, PC, *CM, *CE, *CL, *SO, *SE;
  44.  
  45. TERM term = {
  46.     NULL,    /* these four values are set dynamically at open time */
  47.     NULL,
  48.     NULL,
  49.     NULL,
  50.     MARGIN,
  51.     SCRSIZ,
  52.     NPAUSE,
  53.         tcapopen,
  54.         ttclose,
  55.         tcapkopen,
  56.         tcapkclose,
  57.         ttgetc,
  58.         ttputc,
  59.         ttflush,
  60.         tcapmove,
  61.         tcapeeol,
  62.         tcapeeop,
  63.         tcapbeep,
  64.         tcaprev,
  65.         tcapcres
  66. #if    COLOR
  67.     , tcapfcol,
  68.     tcapbcol
  69. #endif
  70. };
  71.  
  72. tcapopen()
  73.  
  74. {
  75.         char *getenv();
  76.         char *t, *p, *tgetstr();
  77.         char tcbuf[1024];
  78.         char *tv_stype;
  79.         char err_str[72];
  80.  
  81.         if ((tv_stype = getenv("TERM")) == NULL)
  82.         {
  83.                 puts("Environment variable TERM not defined!");
  84.                 exit(1);
  85.         }
  86.  
  87.         if ((tgetent(tcbuf, tv_stype)) != 1)
  88.         {
  89.                 sprintf(err_str, "Unknown terminal type %s!", tv_stype);
  90.                 puts(err_str);
  91.                 exit(1);
  92.         }
  93.  
  94.  
  95.        if ((term.t_nrow=(short)tgetnum("li")-1) == -1){
  96.                puts("termcap entry incomplete (lines)");
  97.                exit(1);
  98.        }
  99.     term.t_mrow =  term.t_nrow;
  100.  
  101.        if ((term.t_ncol=(short)tgetnum("co")) == -1){
  102.                puts("Termcap entry incomplete (columns)");
  103.                exit(1);
  104.        }
  105.     term.t_mcol = term.t_ncol;
  106.  
  107.         p = tcapbuf;
  108.         t = tgetstr("pc", &p);
  109.         if(t)
  110.                 PC = *t;
  111.  
  112.         CL = tgetstr("cl", &p);
  113.         CM = tgetstr("cm", &p);
  114.         CE = tgetstr("ce", &p);
  115.         UP = tgetstr("up", &p);
  116.     SE = tgetstr("se", &p);
  117.     SO = tgetstr("so", &p);
  118.     if (SO != NULL)
  119.         revexist = TRUE;
  120.  
  121.         if(CL == NULL || CM == NULL || UP == NULL)
  122.         {
  123.                 puts("Incomplete termcap entry\n");
  124.                 exit(1);
  125.         }
  126.  
  127.     if (CE == NULL)        /* will we be able to use clear to EOL? */
  128.         eolexist = FALSE;
  129.         
  130.         if (p >= &tcapbuf[TCAPSLEN])
  131.         {
  132.                 puts("Terminal description too big!\n");
  133.                 exit(1);
  134.         }
  135.         ttopen();
  136. }
  137.  
  138. tcapkopen()
  139.  
  140. {
  141.     strcpy(sres, "NORMAL");
  142. }
  143.  
  144. tcapkclose()
  145.  
  146. {
  147. }
  148.  
  149. tcapmove(row, col)
  150. register int row, col;
  151. {
  152.         putpad(tgoto(CM, col, row));
  153. }
  154.  
  155. tcapeeol()
  156. {
  157.         putpad(CE);
  158. }
  159.  
  160. tcapeeop()
  161. {
  162.         putpad(CL);
  163. }
  164.  
  165. tcaprev(state)        /* change reverse video status */
  166.  
  167. int state;        /* FALSE = normal video, TRUE = reverse video */
  168.  
  169. {
  170.     static int revstate = FALSE;
  171.     if (state) {
  172.         if (SO != NULL)
  173.             putpad(SO);
  174.     } else
  175.         if (SE != NULL)
  176.             putpad(SE);
  177. }
  178.  
  179. tcapcres()    /* change screen resolution */
  180.  
  181. {
  182.     return(TRUE);
  183. }
  184.  
  185. #if    COLOR
  186. tcapfcol()    /* no colors here, ignore this */
  187. {
  188. }
  189.  
  190. tcapbcol()    /* no colors here, ignore this */
  191. {
  192. }
  193. #endif
  194.  
  195. tcapbeep()
  196. {
  197.     ttputc(BEL);
  198. }
  199.  
  200. putpad(str)
  201. char    *str;
  202. {
  203.     tputs(str, 1, ttputc);
  204. }
  205.  
  206. putnpad(str, n)
  207. char    *str;
  208. {
  209.     tputs(str, n, ttputc);
  210. }
  211.  
  212.  
  213. #if    FLABEL
  214. fnclabel(f, n)        /* label a function key */
  215.  
  216. int f,n;    /* default flag, numeric argument [unused] */
  217.  
  218. {
  219.     /* on machines with no function keys...don't bother */
  220.     return(TRUE);
  221. }
  222. #endif
  223. #else
  224.  
  225. hello()
  226. {
  227. }
  228.  
  229. #endif TERMCAP
  230.